var UNDO_MANAGER={version:1.24};
function UndoableAction(_410,_411,_412,_413,_414,_415){
this.fStatus=undefined;
this.fName=COMMONS.isString(_414)?_414:undefined;
this.fGroup=_415;
this.fDoMethod=_410;
this.fUndoMethod=_411||_410;
this.fDoParams=COMMONS.isUndefined(_412)||COMMONS.isArray(_412)?_412:[_412];
this.fUndoParams=COMMONS.isUndefined(_413)||COMMONS.isArray(_413)?_413:[_413];
}
UndoableAction.prototype.fLogger=new Logger("UndoableAction");
UndoableAction.STATUS_DO_OK=1;
UndoableAction.STATUS_DO_ERROR=1000;
UndoableAction.STATUS_UNDO_OK=2;
UndoableAction.STATUS_UNDO_ERROR=1001;
UndoableAction.prototype.getGroup=function(){
return this.fGroup;
};
UndoableAction.prototype.getName=function(_416){
return this.fName;
};
UndoableAction.prototype.getStatus=function(){
return this.fStatus;
};
UndoableAction.prototype.callDo=function(){
if(COMMONS.isFunction(this.fDoMethod)){
try{
if(COMMONS.isArray(this.fDoParams)){
this.fDoMethod.apply(this,this.fDoParams);
}else{
this.fDoMethod.call(this);
}
this.fStatus=UndoableAction.STATUS_DO_OK;
}
catch(ex){
this.fStatus=UndoableAction.STATUS_DO_ERROR;
this.fLogger.error("doAction, error happened",ex,this.fDoMethod);
}
}
};
UndoableAction.prototype.callUndo=function(){
if(COMMONS.isFunction(this.fUndoMethod)){
try{
if(COMMONS.isArray(this.fUndoParams)){
this.fUndoMethod.apply(this,this.fUndoParams);
}else{
this.fUndoMethod.call(this);
}
this.fStatus=UndoableAction.STATUS_UNDO_OK;
}
catch(ex){
this.fStatus=UndoableAction.STATUS_UNDO_ERROR;
this.fLogger.error("undoAction, error happened",ex,this.fUndoMethod);
}
}
};
UndoableAction.prototype.isReversible=function(){
var _417=this.fDoMethod===this.fUndoMethod&&COMMONS.isEquals(this.fDoParams,this.fUndoParams);
return _417;
};
UndoableAction.prototype.merge=function(_418){
var _419=false;
if(_418 instanceof UndoableAction){
if(COMMONS.isDefined(this.fGroup)&&this.fGroup===_418.getGroup()&&COMMONS.isDefined(this.fDoParams)){
if(this.fDoMethod===_418.fDoMethod&&this.fUndoMethod===_418.fUndoMethod){
this.fDoParams=_418.fDoParams;
_419=true;
}
}
}else{
this.fLogger.error("merge, illegal agrument type:"+_418);
}
return _419;
};
function UndoManager(_41a){
this.fMaxSize=COMMONS.isNumber(_41a)?_41a:32;
this.fUndoData=[];
this.fRedoData=[];
}
UndoManager.prototype.fLogger=new Logger("UndoManager");
UndoManager.prototype.getUndoStack=function(){
return this.fUndoData;
};
UndoManager.prototype.isUndoFound=function(){
var _41b=this.getUndoStack();
return _41b.length>0;
};
UndoManager.prototype.getRedoStack=function(){
return this.fRedoData;
};
UndoManager.prototype.isRedoFound=function(){
var _41c=this.getRedoStack();
return _41c.length>0;
};
UndoManager.prototype.callDo=function(_41d,aID){
if(_41d instanceof UndoableAction){
try{
_41d.callDo();
if(_41d.getStatus()===UndoableAction.STATUS_DO_OK){
this.addAction(_41d,aID);
}else{
this.processErrorDo(_41d);
}
}
catch(ex){
this.processErrorDo(_41d,ex);
}
}else{
this.fLogger.info("callDo, illegal argument:"+_41d);
}
};
UndoManager.prototype.addAction=function(_41f,aID){
if(_41f instanceof UndoableAction){
var add=true;
if(this.isUndoFound()){
var _422=this.fUndoData[this.fUndoData.length-1].action;
add=!_422.merge(_41f);
if(!add&&_422.isReversible()){
this.fUndoData.length--;
}
}
if(add){
if(!COMMONS.isDefined(_41f.fLogger)){
_41f.fLogger=this.fLogger;
}
var data={id:aID,action:_41f};
var _424=this.getUndoStack();
if(_424.length<this.fMaxSize){
_424.push(data);
}else{
_424.shift(data);
}
if(this.isRedoFound()){
var _422=this.fRedoData[this.fRedoData.length-1].action;
if(!COMMONS.isEquals(_41f,_422)){
this.fRedoData.length=0;
}
}
}
}else{
this.fLogger.info("addAction, illegal argument:"+_41f);
}
};
UndoManager.prototype.callUndo=function(){
if(this.isUndoFound()){
var data=this.getUndoStack().pop();
if(COMMONS.isObject(data)){
var _426=data.action;
try{
_426.callUndo();
if(_426.getStatus()===UndoableAction.STATUS_UNDO_OK){
var _427=this.getRedoStack();
if(_427.length<this.fMaxSize){
_427.push(data);
}else{
_427.shift(data);
}
}else{
this.processErrorUndo(data);
}
}
catch(ex){
this.processErrorUndo(data,ex);
}
}
}else{
this.fLogger.info("callUndo, undo stack is empty");
}
};
UndoManager.prototype.callRedo=function(){
if(this.isRedoFound()){
var data=this.getRedoStack().pop();
if(COMMONS.isObject(data)){
var _429=data.action;
try{
_429.callDo();
if(_429.getStatus()===UndoableAction.STATUS_DO_OK){
var _42a=this.getUndoStack();
if(_42a.length<this.fMaxSize){
_42a.push(data);
}else{
_42a.shift(data);
}
}else{
this.processErrorDo(_429);
}
}
catch(ex){
this.processErrorDo(data,ex);
}
}
}else{
this.fLogger.info("callRedo, redo stack is empty");
}
};
UndoManager.prototype.processErrorUndo=function(_42b,_42c){
};
UndoManager.prototype.processErrorDo=function(_42d,_42e){
};
UndoManager.prototype.clear=function(){
this.getUndoStack().length=0;
this.getRedoStack().length=0;
};
